package com.app.qbake.module.mine;


import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wind.base.mvp.view.BaseLoadingFragment;
import com.wind.base.repo.UserRepo;
import com.wind.base.request.BaseRequest;
import com.wind.base.utils.ViewInflater;
import com.wind.coder.annotations.Api;
import com.wind.coder.annotations.Heros;
import com.wind.coder.annotations.Param;
import com.wind.data.mine.MineRequest;
import com.wind.data.mine.MineResponse;
import com.app.qbake.R;
import com.app.qbake.module.mine.activity.BuyedGoodsActivity;
import com.app.qbake.module.mine.activity.CollectGoodsListActivity;
import com.app.qbake.module.mine.activity.MyGoodsActivity;
import com.app.qbake.module.mine.activity.SettingsActivity;
import com.app.qbake.module.mine.activity.SoldGoodsActivity;
import com.app.qbake.module.mine.activity.UserInfoActivity;
import com.app.qbake.module.mine.activity.VipPkgActivity;
import com.app.qbake.module.mine.activity.WalletActivity;
import com.app.qbake.module.mine.di.MineComponent;
import com.app.qbake.module.mine.mvp.MineView;
import com.app.qbake.module.mine.presenter.MinePresenter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

@Heros(
        param = @Param(
                viewCanonicalName = "com.app.qbake.module.mine.mvp.MineView",
                responseCanonicalName = "com.wind.data.mine.MineResponse",
                requestCanonicalName = "com.wind.data.mine.MineRequest"

        ),
        api = @Api(httpMethod = Api.HttpMethod.GET, url = "user/info")
)
public class MineFragment extends BaseLoadingFragment<MineView, MinePresenter, MineComponent, MineResponse>
        implements MineView {

    @BindView(R.id.tv_goods_num)
    TextView tv_goods_num;
    @BindView(R.id.tv_fans_num)
    TextView tv_fans_num;
    @BindView(R.id.tv_introduce)
    TextView tv_introduce;
    @BindView(R.id.iv_avatar)
    ImageView iv_avatar;
    @Inject
    MinePresenter presenter;

    @Override
    public MinePresenter createPresenter() {
        return presenter;
    }

    @Override
    protected void load() {
        if (UserRepo.getInstance().isLogin(getActivity()))
            super.load();
    }

    @Override
    protected BaseRequest buildLoadingRequest() {
        MineRequest request = new MineRequest();
        return request;
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.fragment_mine;
    }

    @Override
    public void showPage(MineResponse reponse) {
        ViewInflater.inflateText(tv_goods_num, reponse.getData().getShop_number() + "");
        ViewInflater.inflateText(tv_fans_num, reponse.getData().getFollow_number() + "");
        String introduce = reponse.getData().getUserInfo().getIntroduce();
        if ("null".equals(introduce)) {
            introduce = "";
        }
        ViewInflater.inflateText(tv_introduce, introduce);

        ViewInflater.inflateImage(iv_avatar, reponse.getData().getUserInfo().getAvatar());
        mLayoutManager.showContent();
    }


    @OnClick({R.id.fl_info, R.id.layout_vip, R.id.layout_wallet, R.id.layout_settings,
            R.id.layout_publish, R.id.layout_collect, R.id.layout_buyed, R.id.layout_sold})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.layout_sold:
                SoldGoodsActivity.start(getActivity());
                break;
            case R.id.layout_buyed:
                BuyedGoodsActivity.start(getActivity());
                break;
            case R.id.layout_collect:
                CollectGoodsListActivity.start(getActivity());
                break;
            case R.id.layout_publish:
                MyGoodsActivity.start(getActivity());
                break;
            case R.id.layout_settings:
                SettingsActivity.start(getActivity());
                break;
            case R.id.layout_wallet:
                WalletActivity.start(getActivity());
                break;
            case R.id.fl_info:
                UserInfoActivity.start(getActivity());
                break;
            case R.id.layout_vip:
                VipPkgActivity.start(getActivity());
                break;
        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            load();
        }
    }
}
